package com.taobao.livis;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class TestDate {
	public static void main(String[] args) throws ParseException, InterruptedException {
		String startDate = "20111229000000";
		String endDate = "20120106000000";

		StringBuilder sb1 = new StringBuilder();

		sb1.append(startDate.substring(0, 4)).append("-")
				.append(startDate.substring(4, 6)).append("-")
				.append(startDate.substring(6, 8)).append(" ")
				.append(startDate.substring(8, 10)).append(":")
				.append(startDate.substring(10, 12)).append(":")
				.append(startDate.substring(12, 14));
		startDate = sb1.toString();
		StringBuilder sb2 = new StringBuilder();
		sb2.append(endDate.substring(0, 4)).append("-")
				.append(endDate.substring(4, 6)).append("-")
				.append(endDate.substring(6, 8)).append(" ")
				.append(endDate.substring(8, 10)).append(":")
				.append(endDate.substring(10, 12)).append(":")
				.append(endDate.substring(12, 14));
		endDate = sb2.toString();

		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		DateFormat curFormat = new SimpleDateFormat("yyyyMMdd");
		DateFormat lastFormat = new SimpleDateFormat("HHmmss");

		Date start = df.parse(startDate);
		Date end = df.parse(endDate);
		Date currentStart = null;
		Date currentEnd = null;
		Calendar c = Calendar.getInstance();
		c.setTime(start);
		currentStart = start;
		String startDateCur = "";
		String startTimeCur = "";
		String endDateCur = "";
		String endTimeCur = "";

		while (c.getTime().compareTo(end) <= 0) {
			c.add(Calendar.MINUTE, 30);
			currentEnd = c.getTime();
			System.out.println("start:["+currentStart+"]"+"-end["+currentEnd+"]");
			startDateCur = curFormat.format(currentStart);
			startTimeCur = lastFormat.format(currentStart);
			endDateCur = curFormat.format(currentEnd);
			endTimeCur = lastFormat.format(currentEnd);
			System.out.println(startDateCur+startTimeCur+"->"+endDateCur+endTimeCur);
			currentStart = currentEnd;
			Thread.sleep(3000);
		}

		System.out.println("data recovery over!!");
	}
}
